package org.ecnu.java.test;


import java.io.RandomAccessFile;
import java.util.ArrayList;

/*
 * @author Arthur Li
 */

public class DataRead {
	public static int[][] GetData(String FileName) throws Exception {
		RandomAccessFile rFile = new RandomAccessFile(FileName, "r");
		
		ArrayList<Short> arraylist = new ArrayList<Short>();
		int[][] result = new int[512][512];
		long point = rFile.length() - 524288;
		int i = 0, j = 0;
		while (rFile.getFilePointer() < rFile.length()) {
			long p = rFile.getFilePointer();
			if (p < point)
				rFile.readByte();
			else {
				result[i][j++] = getByte(rFile.readByte(),rFile.readByte());
					if (j >= 512) {
					i++;
					j = 0;
				}
			}
		}
		return result;
	}
	public static int getByte(byte a,byte b){
		return (int) ((b& 0xFF)*256+ (a & 0xFF));	
	}
}
